package com.cqggrw.action;

import com.cqggrw.domain.Json;
import com.cqggrw.domain.Link;
import com.cqggrw.service.LinkServiceI;
import com.cqggrw.service.impl.LinkServiceImpl;
import com.opensymphony.xwork2.ModelDriven;

public class LinkAction extends BaseAction implements ModelDriven<Link> {

	private static final long serialVersionUID = 1L;
	private LinkServiceI service = new LinkServiceImpl();
	public Link link = new Link();
	
	public void getList() {
		super.writeJson(service.get());
	}
	
	public String add() {
		if(service.add(link)) {
			super.addAttributeForRequest("message", "添加成功!");
		} else {
			super.addAttributeForRequest("message", "添加失败!");
		}
		return "success";
	}
	
	public String modify() {
		if(service.modify(link)) {
			super.addAttributeForRequest("message", "修改成功!");
		} else {
			super.addAttributeForRequest("message", "修改失败!");
		}
		return "success";
	}
	
	public void delete() {
		Json json = new Json();
		if (service.del(link.getId())) {
			json.setSuccess(true);
			json.setMsg("删除成功!");
		} else {
			json.setSuccess(false);
			json.setMsg("删除失败!");
		}

		super.writeJson(json);
	}

	public Link getModel() {
		return link;
	}

}
